package com.qingcheng.service;

import com.qingcheng.dao.AdditionalCommentMapper;
import com.qingcheng.dao.CommentMapper;
import com.qingcheng.pojo.business.Ad;
import com.qingcheng.pojo.comment.AdditionalComment;
import com.qingcheng.pojo.comment.Comment;
import com.qingcheng.service.comment.AdditionalCommentService;
import com.qingcheng.util.IdWorker;
import jdk.nashorn.internal.ir.annotations.Reference;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;

public class AdditionalCommentServiceImpl implements AdditionalCommentService {


    @Autowired
    private AdditionalCommentMapper additionalCommentMapper;

    @Autowired
    private IdWorker idWorker;

    @Autowired
    private CommentMapper commentMapper;

    /**
     * 追加评论
     *
     * @param additionalComment
     * @return
     */
    @Override
    public void addAdditional(AdditionalComment additionalComment, String username) {

        Comment commentNew = new Comment();
        commentNew.setId(additionalComment.getCommentId());
        Comment comment = commentMapper.selectByPrimaryKey(commentNew);

        if (comment.getUsername() != username) {
            throw new RuntimeException("参数错误");
        }

        if (comment == null) {
            throw new RuntimeException("参数错误");
        }

        comment.setIsAdd(1);
        commentMapper.updateByPrimaryKeySelective(comment);

        additionalComment.setId(idWorker.nextId() + "");
        additionalComment.setCreateTime(new Date());

        additionalCommentMapper.insert(additionalComment);
    }
}
